package com.yizn.learn.springext.getspringcontex.ApplicationContextAware;

import com.yizn.learn.springext.getspringcontex.BeanFactoryAware.Person;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

/**
 * project : my-learn
 * <p> 实现ApplicationContextAware接口，然后重写setApplicationContext方法，也能从该方法中获取到spring容器对象。 </p>
 *
 * @author yisl
 * @date 2023-01-13【星期五】
 **/
@Service
public class PersonService2 implements ApplicationContextAware {
    private ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void add(){
        Person person = (Person) this.applicationContext.getBean("person");
        person.test1();
    }
}
